// Created by wangliang on 2025/4/9.

import 'package:flutter/material.dart';

import '../color/common_color.dart';

class CommonDialog extends Dialog {
  CommonDialog(
    BuildContext context, {
    super.key,
    required String title,
    required String content,
    required String negative,
    Function? negativeTap,
    required String positive,
    Function? positiveTap,
    bool positiveClickCloseDialog = true,
  }) : super(
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
          child: IntrinsicHeight(
            child: Column(
              children: [
                Container(
                  margin: const EdgeInsets.only(top: 28),
                  child: Text(
                    title,
                    style: TextStyle(fontSize: 16, color: CommonColor.std001, fontWeight: FontWeight.w500),
                  ),
                ),
                Expanded(
                  child: SingleChildScrollView(
                    child: Container(
                      margin: const EdgeInsets.only(top: 20, left: 24, right: 24, bottom: 28),
                      child: Text(
                        content,
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 16, color: CommonColor.std002),
                      ),
                    ),
                  ),
                ),
                Container(
                  height: 0.5,
                  width: double.infinity,
                  color: const Color(0xFFDCE1E5),
                ),
                Row(
                  children: [
                    if (negative.isNotEmpty)
                      Expanded(
                        child: GestureDetector(
                          onTap: () {
                            Navigator.of(context).pop();
                            negativeTap?.call();
                          },
                          child: Container(
                            height: 56,
                            alignment: Alignment.center,
                            decoration: const BoxDecoration(
                                borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(20),
                                ),
                                color: Colors.white),
                            child: Text(
                              negative,
                              style: const TextStyle(
                                fontSize: 17,
                                color: Colors.black,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ),
                        ),
                      ),
                    if (negative.isNotEmpty)
                      Container(
                        width: 0.5,
                        height: 56,
                        color: const Color(0xFFDCE1E5),
                      ),
                    Expanded(
                      child: GestureDetector(
                        onTap: () {
                          if (positiveClickCloseDialog) {
                            Navigator.of(context).pop();
                          }
                          positiveTap?.call();
                        },
                        child: Container(
                          height: 56,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(negative.isNotEmpty ? 0 : 20),
                                bottomRight: const Radius.circular(20),
                              ),
                              color: Colors.white),
                          child: Text(
                            positive,
                            style: const TextStyle(
                              fontSize: 17,
                              color: Color(0xFF905300),
                              fontWeight: FontWeight.w500,
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
        );
}
